# -*- coding: utf-8 -*-
import os
debug = True
secret_key = '\xfd|\x1f9\x85\xab\x06Jq(\xeb\x98Ft\x83_\xdc\xad8\t'

# 获取当前目录
from os.path import abspath, dirname, join
base_path = abspath(dirname(__file__))

# 添加系统路径
import sys
sys.path.insert(0, abspath(join(base_path, '..', '..', '..')))

# 配置session
from accost.sessions import GAESessionStore, MemorySessionStore, BDBSessionStore, SessionStore
session_store = MemorySessionStore()

# 设置模板目录
from accost.utils.tmpl import FragmentCacheExtension
from jinja2 import Environment, FileSystemLoader
env = Environment(
    loader      =   FileSystemLoader(join(base_path, 'templates')),
    extensions  =   [FragmentCacheExtension],
    auto_reload =   debug
)

# database configuration
from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.pool import NullPool, SingletonThreadPool, StaticPool
#dburi = "mysql://user:password@127.0.0.1/db?charset=utf8&use_unicode=0"
#dburi = "sqlite://"
dburi = "mysql://root:123@127.0.0.1/aisino?charset=utf8&use_unicode=0"
engine = create_engine(
    dburi,
    convert_unicode=True,
    encoding="utf-8",
    pool_recycle=3600*7,
    #echo_pool=True,
    echo=False,
)
metadata = MetaData(bind=engine)
session = scoped_session(sessionmaker(engine))
sqlalchemy_sessions = [session]

from accost import Rules
home = Rules()

# 设置缓存
from accost.cache import GAECache, MemcacheCache, DummyCache
#cache = MemcacheCache(["127.0.0.1:11211"])
#cache = GAECache()
cache = DummyCache()
env.fragment_cache = cache

# 设置中间件
middlewares = [
    "accost.middlewares.TimeMiddleware"
]

